﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TvTipper.Api;
using TvTipper.Entities;
using TvTipper.Core;

namespace TvTipper.Testing
{
    public partial class TestDataPortal : IDataAccessPortal
    {
        private Random m_rand = new Random();

        public IList<PersonMetadata> SearchPersonsByName(string name)
        {
            return Persons.Select(p => p.GetMetadata()).ToList();
        }

        public Person GetPersonById(string id)
        {
            // get the person
            var person = Persons.Where(p => p.Id.Equals(id)).FirstOrDefault();

            // set (semi) randomly roles
            //var rtp = RolesToPrograms.ToList();
            //int i = m_rand.Next() % rtp.Count;
            //person.RoleToPrograms = rtp[i];

            return person;
        }

        public IList<TvProgramMetadata> SearchTvProgram(TvProgramSearchQuery query)
        {
            return Programs.Select(p => p.GetMetadata()).ToList();
        }

        public TvProgram GetTvProgramById(string id)
        {
            return Programs.Where(p => p.Id.Equals(id)).FirstOrDefault();
        }

        public IList<LookupEntity> getLookupByKey(LookupType type){
            if (type == LookupType.Genere)
            {
                return Generes.ToList();
            }

            if (type == LookupType.Role)
            {
                return Roles.ToList();
            }

            return null;
        }
     

        public IList<TvProgramMetadata> GetTopTvPrograms(int from, int to)
        {
            try
            {
                return Programs.Where(p => p.OverRank >= 4).
                    Select(p => p.GetMetadata()).
                    ToList();
            }
            finally
            {
                Services.EntityManager.RecommandationUpdated = true;
            }
        }


        public void RankEntity(RankableEntity entity, int rank)
        {
        }

        public IDictionary<string, float> GetRankFactors()
        {
            return null;
        }


        public void SetRankFactors(IDictionary<string, float> factors)
        {
        }

        public void UpdatePerson(Person person)
        {
        }

        public void UpdateProgram(TvProgram program)
        {
        }
    }
}
